package bTree.LeetCode;

import java.util.Arrays;


public class 缺失的第一个正数 {
    public int firstMissingPositive(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            while (nums[i]>0&&nums[i]<=nums.length&&nums[i]!=i+1){
                int temp=nums[nums[i]-1];
                if (temp==nums[i]){
                    break;
                }
                nums[nums[i]-1]=nums[i];
                nums[i]=temp;
            }
        }
        for (int i = 0; i < nums.length; i++) {
            if (nums[i]!=i+1){
                return i+1;
            }
        }
        return nums.length+1;
    }
}